package com.zoe.onelink.business.util;

import com.zoe.onelink.util.OnelinkContextHolder;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>标题: 线程变量工具类</p>
 * <p>描述: 请使用 {@link OnelinkContextHolder}替代</p>
 * <p>版权: Copyright (c) 2016</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: cxy
 * @date 2016/10/26
 */
@Deprecated
public class ThreadParameterUtil {

    private ThreadParameterUtil() {

    }

    /**
     * 设置线程变量值Map集合
     *
     * @param parameterMap 变量值map
     */
    public static void set(Map<String, String> parameterMap) {
        OnelinkContextHolder.putValue((Map) parameterMap);
    }

    public static void setMulti(Map<String, String> paramMap) {
        OnelinkContextHolder.putValue((Map) paramMap);
    }


    /**
     * 设置线程变量值
     *
     * @param key   键
     * @param value 值
     */
    public static void set(String key, String value) {
        OnelinkContextHolder.putValue(key, value);
    }

    /**
     * 获取线程变量值map集合
     */
    public static Map<String, String> getParameterMap() {
        return OnelinkContextHolder.getCopiedMap().entrySet().stream()
                .collect(Collectors.toMap(Map.Entry::getKey, (e) -> e.getValue() == null ? "" : e.getValue().toString()));
    }

    /**
     * 获取线程变量值
     *
     * @param key 键
     */
    public static String get(String key) {
        return OnelinkContextHolder.getString(key);
    }

    /**
     * 设置线程变量值
     *
     * @param key   键
     * @param value 值
     */
    public static void refreshParameter(String key, String value) {
        // do-nothing
    }

    public static void clear() {
        OnelinkContextHolder.clear();
    }
}
